package com.pkk.penguin.frame.know.java.jvm.runtimedata;

import org.junit.Test;

/**
 * @description: 操作数栈与局部变量表
 * @author: peikunkun
 * @create: 2020-02-25 09:59
 **/
public class OperandStack {


  public static void main(String[] args) {
    OperandStack operandStack = new OperandStack();
    System.out.println(operandStack.add());
  }


  public void iadd() {
    /**
     *  0 bipush 10
     *  2 istore_1
     *  3 iinc 1 by 1  此操作只会改变局部变量表的数据,不会改变栈中的数据
     *  6 bipush 11
     *  8 istore_2
     *  9 iinc 2 by 1
     *  -------------------------------------
     * 12 bipush 12      //12入栈
     * 14 istore_3      //12操作到局部变量表
     * 15 iload_3       //加载局部变量表的索引为3的入栈
     * 16 iinc 3 by 1   //局部变量表进行加加操作
     * 19 istore 4      //
     * 21 bipush 13
     * 23 istore 5
     * 25 iinc 5 by 1
     * 28 iload 5
     * 30 istore 6
     *  -------------------------------------
     * 32 bipush 14
     * 34 istore 7
     * 36 iload 7
     * 38 iinc 7 by 1
     * 41 istore 7
     * 43 bipush 15
     * 45 istore 8
     * 47 iinc 8 by 1
     * 50 iload 8
     * 52 istore 8
     * 54 bipush 16
     * 56 istore 9
     * 58 iload 9
     * 60 iinc 9 by 1
     * 63 iinc 9 by 1
     * 66 iload 9
     * 68 iadd
     * 69 istore 10
     * 71 return
     */
    //第一类问题
    int a1 = 10;
    a1++;

    int a2 = 11;
    ++a2;
    //System.out.println(a1);
    //System.out.println(a2);

    //第二类问题
    int b1 = 12;
    int b11 = b1++;

    int b2 = 13;
    int b21 = ++b2;
    //System.out.println(b1);
    //System.out.println(b11);
    //System.out.println(b2);
    //System.out.println(b21);

    //第三类问题
    int c1 = 14;
    c1 = c1++;

    int c2 = 15;
    c2 = ++c2;
    //System.out.println(c1);
    //System.out.println(c2);

    //第四类问题
    int d1 = 16;
    int d2 = d1++ + ++d1;
    //System.out.println(d1);
    //System.out.println(d2);
  }


  public int add() {
    byte a = 127;
    byte b = -128;
    int c = a + b;
    return c;
  }


  public void iadd2() {
    /**
     *  0 bipush 12
     *  2 istore_1
     *  3 iload_1
     *  ------------------------------------差别1开始
     *  4 iinc 1 by 1
     *  7 istore_2
     *  ------------------------------------差别1结束
     *  8 bipush 13
     * 10 istore_3
     * ------------------------------------差别2开始
     * 11 iinc 3 by 1
     * 14 iload_3
     * 15 istore 4
     * ------------------------------------差别2结束
     * 17 return
     */
    int b1 = 12;
    int b11 = b1++;

    int b2 = 13;
    int b21 = ++b2;
  }


  @Test
  public void Administrator_130_20200226100345() {
    /**
     *  0 bipush 16
     *  2 istore_1
     *  3 iload_1
     *  4 iinc 1 by 1
     *  7 iinc 1 by 1
     * 10 iload_1
     * 11 iadd
     * 12 istore_2
     * 13 return
     */
    /**
     * 分析对比图
     * 操作数栈(右为栈顶)   |   局部变量表(元素之间这里逗号隔开)
     *    16
     *                              16
     *    16,16                     16
     *                              17
     *    16,16                     18
     *    16,16,18                  18
     *    16+18                     18
     *    16+18                     18,34
     */

    int d1 = 16;
    int d2 = d1++ + ++d1;
    System.out.println(d1);
    System.out.println(d2);
  }
}
